package jdbc;

import java.sql.*;
import java.util.Scanner;

import util.DBUtil;

public class InsertStudent {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in

		);
		System.out.print("请输入的姓名:");
		String sname = sc.nextLine();
		System.out.print("请输入性别：");
		String sex = sc.nextLine();
		System.out.print("请输入手机号:");
		String tel = sc.nextLine();
		System.out.print("请输入年级:");
		int gradeid = sc.nextInt();
		sc.nextLine();
		System.out.print("请输入生日:");
		String date = sc.nextLine();
		System.out.print("请输入密码:");
		String pass = sc.nextLine();
		System.out.println("input wechat number:");
		String wechat = sc.nextLine();
		Connection con = DBUtil.getConnection();
		PreparedStatement st = null;
		int rs = 0;
		String sql = "insert into student (fromcity,wechat,address,sname,sex,telephone,gradeid,birthday,pass) values (?,?,?,?,?,?,?,str_to_date(?,'%Y-%m-%d'),?)";

		try {
			int index = 1;
			st = con.prepareStatement(sql);
			st.setString(index++, "合肥");
			st.setString(index++, wechat);
			st.setString(index++, "包河区");
			st.setString(index++, sname);
			st.setString(index++, sex);
			st.setString(index++, tel);
			st.setInt(index++, gradeid);
			st.setString(index++, date);
			st.setString(index++, pass);
			rs = st.executeUpdate();
			System.out.println(sql);
			System.out.println("插入了" + rs + "条");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DBUtil.close(st);
			DBUtil.close(con);
		}

	}
}
